public class test07 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
        int res;
        TreeNode pre;
        public int getMinimumDifference(TreeNode root) {
            //递归法
            res = Integer.MAX_VALUE;
            traversal(root);
            return res;
        }
        private void traversal(TreeNode root){
            if(root==null){
                return;
            }
            traversal(root.left);
            if(pre!=null){
                res = Math.min(res,Math.abs(root.val-pre.val));
            }
            pre = root;
            traversal(root.right);
        }
}
